#include "TDxBuffer.h"

HRESULT TDxBuffer::Create(	ID3D10Device* pDevice,
							UINT iSize, 
							UINT iCounter, 
							void* pPoint, 
							UINT  BindFlags,
							D3D10_USAGE Usage,
							ID3D10Buffer** ppGetBuffer )
{
	assert( pPoint || iCounter > 0 );
	HRESULT hr;

	ID3D10Buffer**  ppBuffer = ppGetBuffer;
	
	if( ppBuffer == NULL ) 
	{
		/*if( BindFlags == D3D10_BIND_VERTEX_BUFFER )
		{
			ppBuffer = &m_pVertexBuffer;
		}
		if( BindFlags == D3D10_BIND_INDEX_BUFFER )
		{
			ppBuffer = &m_pIndexBuffer;
		}	*/
		ppBuffer = &m_pBuffer;
	}

	m_iCount = iCounter;

    D3D10_BUFFER_DESC bd;
    bd.Usage			= Usage;
    bd.ByteWidth		= iSize * iCounter;
    bd.BindFlags		= BindFlags;
	if( Usage == D3D10_USAGE_DYNAMIC)
		bd.CPUAccessFlags	= D3D10_CPU_ACCESS_WRITE;
	else
		bd.CPUAccessFlags	= 0;
    bd.MiscFlags		= 0;

    D3D10_SUBRESOURCE_DATA InitData;
	ZeroMemory( &InitData, sizeof( D3D10_SUBRESOURCE_DATA ) );
    InitData.pSysMem	 = pPoint;

    hr = pDevice->CreateBuffer( &bd, &InitData, ppBuffer );
    if( FAILED( hr ) )
	{
        return hr;
	}	
	return S_OK;
}
bool TDxBuffer::Release()
{
	SAFE_RELEASE(m_pBuffer);
	return true;
}
TDxBuffer::TDxBuffer(void)
{
	m_pBuffer		= NULL;
	m_iCount			= 0;
}

TDxBuffer::~TDxBuffer(void)
{
	Release();
}
